import java.util.Arrays;
import java.util.Random;

public class timeTest {
    //有序
    public static void initArrayOrder(int[] array) {
        for (int i = 0; i < array.length; i++) {
            array[i] = i;
        }
    }
    //乱序
    public static void initArrayNotOrder(int[] array) {
        Random random = new Random();
        for (int i = 0; i < array.length; i++) {
            array[i] = random.nextInt(10_0000);
        }
    }
    public static void testInsertSort(int[] array) {
        array = Arrays.copyOf(array, array.length);
        //copyOf 重新建立一个数组 , 不影响之前数组
        long startTime = System.currentTimeMillis();
        Sort.insertSort(array);
        long endTime = System.currentTimeMillis();
        System.out.println("直接插入排序耗时:" + (endTime-startTime));
    }
    public static void testShellSort(int[] array) {
        array = Arrays.copyOf(array,array.length);
        long startTime = System.currentTimeMillis();
        Sort.shellSort(array);
        long endTime  = System.currentTimeMillis();
        System.out.println("希尔排序耗时："+ (endTime-startTime));
    }
    public static void testSelectSort(int[] array) {
        array = Arrays.copyOf(array,array.length);
        long startTime = System.currentTimeMillis();
        Sort.selectSort(array);
        long endTime = System.currentTimeMillis();
        System.out.println("直接选择排序耗时："+ (endTime-startTime));
    }
    public static void testHeapSort(int[] array) {
        array = Arrays.copyOf(array,array.length);
        long startTime = System.currentTimeMillis();
        Sort.heapSort(array);
        long endTime = System.currentTimeMillis();
        System.out.println("堆排序耗时："+ (endTime-startTime));
    }
    public static void testBubbbleSort(int[] array) {
        array = Arrays.copyOf(array,array.length);
        long startTime = System.currentTimeMillis();
        Sort.bubbleSort(array);
        long endTime = System.currentTimeMillis();
        System.out.println("冒泡排序耗时："+ (endTime-startTime));
    }

    public static void main(String[] args) {
        int[] array = new int[10_0000];
        initArrayNotOrder(array);
        //initArrayOrder(array);
        testInsertSort(array);
        testShellSort(array);
        testSelectSort(array);
        testHeapSort(array);
        testBubbbleSort(array);
    }
}
